import { _decorator, Component, instantiate, Node, Prefab } from 'cc';
import { UIManager } from '../common/UIManager';
import AllyApi from '../api/AllyApi';
import { Ally, AllyOperateType } from '../entity/Ally';
import { MemberItem } from './MemberItem';
import { AllyUser } from '../entity/AllyUser';
const { ccclass, property } = _decorator;

@ccclass('MemberList')
export class MemberList extends Component {

    @property(Node)
    content:Node
    @property(Prefab)
    memberItem:Prefab

    start() {
        this.query()
    }

    async query(){
        await UIManager.instance.showLoading()
        let res = await AllyApi.Execute({
            op: AllyOperateType.Query
        })
        UIManager.instance.closeLoading()
        console.log(res)

        let ally = new Ally()
        ally.AllyId = res.data.ao.allyId
        ally.AllyName = res.data.ao.allyName

        let list = res.data.ao.AllyUser
        let index = 0
        for(let item of list){
            index ++
            let node = instantiate(this.memberItem)
            this.content.addChild(node)
            let allyUser = AllyUser.createByObj(item)
            allyUser.Rank = index
            node.getComponent(MemberItem).setData(allyUser, ally)
        }
    }
   
}


